<template>
  <div class="app-container">
    <el-form
      :model="queryParams"
      ref="queryForm"
      :inline="true"
      v-show="showSearch"
      label-width="68px"
    >
      <el-form-item label="物料名称" prop="name">
        <el-input
          v-model="queryParams.name"
          placeholder="请输入物料名称"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="生产工单" prop="productionOrder">
        <el-input
          v-model="queryParams.productionOrder"
          placeholder="请输入生产工单"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button
          type="cyan"
          icon="el-icon-search"
          size="mini"
          @click="handleQuery"
          >搜索</el-button
        >
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
          >重置</el-button
        >
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['prodmanage:up:add']"
          >新增</el-button
        >
      </el-col>

      <el-col :span="1.5">
        <el-button
          type="success"
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['prodmanage:up:add']"
          >退料</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdatee"
          v-hasPermi="['prodmanage:up:edit']"
        >修改</el-button>
      </el-col>
                  <el-col :span="1.5">
        <el-button
          type="danger"
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['prodmanage:up:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['prodmanage:up:export']"
          >导出</el-button
        >
      </el-col>
      <right-toolbar
        :showSearch.sync="showSearch"
        @queryTable="getList"
      ></right-toolbar>
    </el-row>

    <el-table
      v-loading="loading"
      :data="upList"
      @selection-change="handleSelectionChange"
    >
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column
        label="领料类型"
        align="center"
        prop="pickingType"
        :formatter="pickingTypeFormat"
        sortable
        width="150"
      />
      <el-table-column
        label="领料部门"
        align="center"
        prop="pickingDepartment"
        sortable
        width="150"
      />
      <el-table-column
        label="所属车间"
        align="center"
        prop="workshop"
        sortable
        width="150"
      />
      <el-table-column
        label="产线"
        align="center"
        prop="prodLine"
        sortable
        width="150"
      />
      <el-table-column
        label="物料代码"
        align="center"
        prop="code"
        sortable
        width="150"
      />
      <el-table-column
        label="物料名称"
        align="center"
        prop="name"
        sortable
        width="150"
      />
      <el-table-column
        label="规格型号"
        align="center"
        prop="goodsModel"
        sortable
        width="150"
      />
      <el-table-column
        label="生产工单"
        align="center"
        prop="productionOrder"
        sortable
        width="150"
      />
      <el-table-column
        label="上料数量"
        align="center"
        prop="loadingQuantity"
        sortable
        width="150"
      />
      <el-table-column
        label="申请数量"
        align="center"
        prop="applyNum"
        sortable
        width="150"
      />
      <el-table-column
        label="实发数量"
        align="center"
        prop="actualNum"
        sortable
        width="150"
      />
      <el-table-column
        label="单位"
        align="center"
        prop="unit"
        sortable
        width="150"
      />
      <el-table-column
        label="发料仓库"
        align="center"
        prop="lssuingWarehouse"
        sortable
        width="150"
      />
      <el-table-column
        label="可用库存"
        align="center"
        prop="availableStock"
        sortable
        width="150"
      />
      <!-- <el-table-column label="仓位" align="center" prop="position" sortable width="150"/> -->
      <!-- <el-table-column label="工序号" align="center" prop="procedureNum" sortable width="150"/>
      <el-table-column label="工序" align="center" prop="workProcedure" sortable width="150"/> -->
      <!-- <el-table-column label="创建时间" align="center" prop="createTime" width="150" sortable>
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="创建人" align="center" prop="createUser" />
      <el-table-column label="修改时间" align="center" prop="updateTime" width="150" sortable>
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.updateTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="修改人" align="center" prop="updateUser" sortable width="150"/> -->
      <el-table-column
        label="审核状态"
        align="center"
        prop="auditStatus"
        :formatter="auditStatusFormat"
        sortable
        width="150"
      />
      <!-- <el-table-column label="上料id" align="center" prop="upId" />
      <el-table-column label="物料id" align="center" prop="goodsId" /> -->
      <!-- <el-table-column label="助记码" align="center" prop="auxiliaryCode" /> -->
      <!-- <el-table-column label="原单单号" align="center" prop="originalOrder" /> -->
      <!-- <el-table-column label="是否返工" align="center" prop="isRework" />
      <el-table-column label="成本对象" align="center" prop="costObject" />
      <el-table-column label="成本对象代码" align="center" prop="costCode" />
      <el-table-column label="产品规格型号" align="center" prop="productModel" />
      <el-table-column label="成本对象组" align="center" prop="costGroup" />
      <el-table-column label="work号" align="center" prop="workNum" />
      <el-table-column label="项目编号" align="center" prop="projectCode" /> -->
      <!-- <el-table-column label="辅助单位" align="center" prop="auxiliaryUnit" />
      <el-table-column label="换算率" align="center" prop="conversionRate" />
      <el-table-column label="辅助数量" align="center" prop="auxiliaryNum" />
      <el-table-column label="计划单价" align="center" prop="planUnivalence" />
      <el-table-column label="计划价金额" align="center" prop="planPrice" />
      <el-table-column label="单价" align="center" prop="univalence" />
      <el-table-column label="金额" align="center" prop="price" />
      <el-table-column label="客户bom" align="center" prop="customerBom" />
      <el-table-column label="备注" align="center" prop="remark" />
      <el-table-column label="生产/采购日期" align="center" prop="date" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.date, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="保质期" align="center" prop="guaranteePeriod" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.guaranteePeriod, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="有效期至" align="center" prop="expiryDate" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.expiryDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column> -->
      <!-- <el-table-column label="成本中心" align="center" prop="costCenter" />
      <el-table-column label="位置号" align="center" prop="locationNum" />
      <el-table-column label="还料尺寸" align="center" prop="returnDimension" />
      <el-table-column label="还料书" align="center" prop="returnBook" />
      <el-table-column label="已复核数量" align="center" prop="checkedQuantity" /> -->
      <!-- <el-table-column label="打印次数" align="center" prop="printsNumber" />
      <el-table-column label="对方科目" align="center" prop="oppositeAccount" />
      <el-table-column label="倒冲标记" align="center" prop="backflushMark" /> -->
      <!-- <el-table-column label="领料用途" align="center" prop="pickingUse" />
      <el-table-column label="原单类型" align="center" prop="originalType" /> -->
      <!-- <el-table-column label="选单号" align="center" prop="menuNum" /> -->
      <!-- <el-table-column
        label="操作"
        align="center"
        class-name="small-padding fixed-width"
      >
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['prodmanage:up:edit']"
            >修改</el-button
          >
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['prodmanage:up:remove']"
            >删除</el-button
          >
        </template>
      </el-table-column> -->
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改生产管理生产上料对话框 -->
    <el-dialog
      :title="title"
      :visible.sync="open"
      width="1000px"
      append-to-body
    >
      <el-form
        :inline="true"
        ref="form"
        :model="form"
        :rules="rules"
        label-width="80px"
      >
         
        <el-form-item label="生产工单" prop="productionOrder">
          <el-select
            v-model="form.productionOrder"
            placeholder="请选择生产任务单号"
          >
            <el-option
              v-for="dict in productionOrderOptions"
              :key="dict.prodorderNo"
              :label="dict.prodorderNo"
              :value="dict.prodorderNo"
            ></el-option>
          </el-select>
        </el-form-item>


        <el-form-item label="物料" prop="name">
          <el-select
            v-model="form.name"
            placeholder="请选择物料"
            style="width: 100%"
            @change="addwarehouse"
          >
            <el-option
              v-for="dict in goodsOptionss"
              :key="dict.goodsId"
              :label="`${dict.fullName}---${dict.goodsCode}---${dict.goodsModel}`"
              :value="`${dict.goodsId}|${dict.fullName}|${dict.goodsCode}|${dict.goodsModel}`"
            ></el-option>
          </el-select>
        </el-form-item>

                <el-form-item label="发料仓库" prop="lssuingWarehouse">
          <el-select
            v-model="form.lssuingWarehouse"
            placeholder="请选择发料仓库"
          >
            <el-option
              v-for="dict in WarehouseOptions"
              :key="dict.name"
              :label="dict.name"
              :value="dict.name"
            ></el-option>
          </el-select>
        </el-form-item>




        <el-form-item label="申请数量" prop="applyNum">
          <el-input v-model="form.applyNum" placeholder="请输入申请数量" />
        </el-form-item>

        <el-form-item :label="upNum" prop="actualNum">
          <el-input v-model="form.actualNum" placeholder="请输入实发数量" />
        </el-form-item>

        <el-form-item label="单位" prop="unit">
          <el-input v-model="form.unit" placeholder="请输入单位" />
        </el-form-item>

        <el-form-item label="上料数量" prop="loadingQuantity">
          <el-input
            v-model="form.loadingQuantity"
            placeholder="请输入上料数量"
          />
        </el-form-item>

        <el-form-item label="可用库存" prop="availableStock">
          <el-input
            v-model="form.availableStock"
            placeholder="请输入可用库存"
          />
        </el-form-item>

        <el-form-item label="辅助单位" prop="auxiliaryUnit">
          <el-input v-model="form.auxiliaryUnit" placeholder="请输入辅助单位" />
        </el-form-item>

        <el-form-item label="辅助数量" prop="auxiliaryNum">
          <el-input v-model="form.auxiliaryNum" placeholder="请输入辅助数量" />
        </el-form-item>

        <el-form-item label="备注" prop="remark">
          <el-input
            v-model="form.remark"
            type="text"
            placeholder="请输入内容"
          />
        </el-form-item>

        <el-form-item label="采购日期" prop="date">
          <el-date-picker
            clearable
            size="small"
            style="width: 200px"
            v-model="form.date"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="选择生产/采购日期"
          >
          </el-date-picker>
        </el-form-item>

        <el-form-item label="领料部门" prop="pickingDepartment">
          <el-select
            v-model="form.pickingDepartment"
            placeholder="请输入领料部门"
            style="width: 100%"
          >
            <el-option
              v-for="dict in pickingDepartmentOptions"
              :key="dict.workshopId"
              :label="`${dict.fullName}        ${dict.workshopName}        ${dict.prodlineName}`"
              :value="`${dict.fullName}|${dict.workshopName}|${dict.prodlineName}`"
            ></el-option>
          </el-select>
        </el-form-item>

        <el-form-item label="领料用途" prop="pickingUse">
          <el-input v-model="form.pickingUse" placeholder="请输入领料用途" />
        </el-form-item>

        <!-- <el-form-item label="来源" prop="source">
          <el-input v-model="form.source" placeholder="请输入来源" />
        </el-form-item> -->
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>

      <!-- 添加或修改生产管理生产上料对话框 -->
    <el-dialog
      :title="title"
      :visible.sync="open1"
      width="1000px"
      append-to-body
    >
      <el-form
        :inline="true"
        ref="form1"
        :model="form1"
        :rules="rules1"
        label-width="80px"
      >
         
        <el-form-item label="生产工单" prop="productionOrder">
          <el-select
            v-model="form1.productionOrder"
            placeholder="请选择生产任务单号"
          >
            <el-option
              v-for="dict in productionOrderOptions"
              :key="dict.prodorderNo"
              :label="dict.prodorderNo"
              :value="dict.prodorderNo"
            ></el-option>
          </el-select>
        </el-form-item>


        <el-form-item label="物料" prop="name">
          <el-select
            v-model="form1.name"
            placeholder="请选择物料"
            style="width: 100%"
            @change="addwarehouse"
          >
            <el-option
              v-for="dict in goodsOptionss"
              :key="dict.goodsId"
              :label="`${dict.fullName}---${dict.goodsCode}---${dict.goodsModel}`"
              :value="`${dict.goodsId}|${dict.fullName}|${dict.goodsCode}|${dict.goodsModel}`"
            ></el-option>
          </el-select>
        </el-form-item>

                <el-form-item label="发料仓库" prop="lssuingWarehouse">
          <el-select
            v-model="form1.lssuingWarehouse"
            placeholder="请选择发料仓库"
          >
            <el-option
              v-for="dict in WarehouseOptions"
              :key="dict.name"
              :label="dict.name"
              :value="dict.name"
            ></el-option>
          </el-select>
        </el-form-item>




        <el-form-item label="申请数量" prop="applyNum">
          <el-input v-model="form1.applyNum" placeholder="请输入申请数量" />
        </el-form-item>

        <el-form-item :label="upNum" prop="actualNum">
          <el-input v-model="form1.actualNum" placeholder="请输入实发数量" />
        </el-form-item>

        <el-form-item label="单位" prop="unit">
          <el-input v-model="form1.unit" placeholder="请输入单位" />
        </el-form-item>

        <el-form-item label="上料数量" prop="loadingQuantity">
          <el-input
            v-model="form1.loadingQuantity"
            placeholder="请输入上料数量"
          />
        </el-form-item>

        <el-form-item label="可用库存" prop="availableStock">
          <el-input
            v-model="form1.availableStock"
            placeholder="请输入可用库存"
          />
        </el-form-item>

        <el-form-item label="辅助单位" prop="auxiliaryUnit">
          <el-input v-model="form1.auxiliaryUnit" placeholder="请输入辅助单位" />
        </el-form-item>

        <el-form-item label="辅助数量" prop="auxiliaryNum">
          <el-input v-model="form1.auxiliaryNum" placeholder="请输入辅助数量" />
        </el-form-item>

        <el-form-item label="备注" prop="remark">
          <el-input
            v-model="form1.remark"
            type="text"
            placeholder="请输入内容"
          />
        </el-form-item>

        <el-form-item label="采购日期" prop="date">
          <el-date-picker
            clearable
            size="small"
            style="width: 200px"
            v-model="form1.date"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="选择生产/采购日期"
          >
          </el-date-picker>
        </el-form-item>

        <el-form-item label="领料部门" prop="pickingDepartment">
          <el-select
            v-model="form1.pickingDepartment"
            placeholder="请输入领料部门"
            style="width: 100%"
          >
            <el-option
              v-for="dict in pickingDepartmentOptions"
              :key="dict.workshopId"
              :label="`${dict.fullName}        ${dict.workshopName}        ${dict.prodlineName}`"
              :value="`${dict.fullName}|${dict.workshopName}|${dict.prodlineName}`"
            ></el-option>
          </el-select>
        </el-form-item>

        <el-form-item label="领料用途" prop="pickingUse">
          <el-input v-model="form1.pickingUse" placeholder="请输入领料用途" />
        </el-form-item>

        <!-- <el-form-item label="来源" prop="source">
          <el-input v-model="form.source" placeholder="请输入来源" />
        </el-form-item> -->
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitFormm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {
  listgood,
  listUp,
  getUp,
  delUp,
  addUp,
  returnGoods,
  exportUp,
  listprod,
  listWarehouse,
  listpickingDepartment,
  listnum,
  updateUp,
} from "@/api/prodmanage/up";

export default {
  name: "Up",
  components: {},
  data() {
    return {
      // 遮罩层
      loading: true,
      //上料标签
      upNum: "实发数量",
      // 选中数组
      ids: [],
      //物料
      goodsOptionss: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 生产管理生产上料表格数据
      upList: [],
      //发料仓库
      WarehouseOptions: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      open1:false,
      //是否显示退料弹出
      aaa: false,
      // 审核状态字典
      auditStatusOptions: [],
      //领料部门车间
      pickingDepartmentOptions: [],
      // 领料类型字典
      pickingTypeOptions: [],
      //库存数量
      numrOptions: [],
      //生产任务单
      productionOrderOptions: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        goodsId: undefined,
        code: undefined,
        auxiliaryCode: undefined,
        name: undefined,
        goodsModel: undefined,
        originalOrder: undefined,
        productionOrder: undefined,
        loadingQuantity: undefined,
        applyNum: undefined,
        actualNum: undefined,
        unit: undefined,
        lssuingWarehouse: undefined,
        isRework: undefined,
        costObject: undefined,
        costCode: undefined,
        productModel: undefined,
        costGroup: undefined,
        workNum: undefined,
        projectCode: undefined,
        availableStock: undefined,
        auxiliaryUnit: undefined,
        conversionRate: undefined,
        auxiliaryNum: undefined,
        planUnivalence: undefined,
        planPrice: undefined,
        univalence: undefined,
        price: undefined,
        customerBom: undefined,
        remark: undefined,
        date: undefined,
        guaranteePeriod: undefined,
        expiryDate: undefined,
        position: undefined,
        procedureNum: undefined,
        workProcedure: undefined,
        costCenter: undefined,
        locationNum: undefined,
        returnDimension: undefined,
        returnBook: undefined,
        checkedQuantity: undefined,
        createTime: undefined,
        createUser: undefined,
        updateTime: undefined,
        updateUser: undefined,
        isDel: undefined,
        auditStatus: undefined,
        printsNumber: undefined,
        oppositeAccount: undefined,
        backflushMark: undefined,
        pickingType: undefined,
        pickingDepartment: undefined,
        pickingUse: undefined,
        originalType: undefined,
        workshop: undefined,
        menuNum: undefined,
        prodLine: undefined,
        source: undefined,
        goodsOptions: undefined,
        pickingDepartment: undefined,
      },
      // 表单参数
      form: {},
      form1:{},
      // 表单校验
      rules: {
        name: [{ required: true, message: "物料不能为空", trigger: "change" }],
        pickingDepartment: [
          { required: true, message: "部门不能为空", trigger: "change" },
        ],
        lssuingWarehouse: [
          { required: true, message: "发料仓库不能为空", trigger: "change" },
        ],
      },
      rules1:{},
    };
  },
  created() {
    this.getList();
    this.getDicts("prodmanage_audit_status").then((response) => {
      this.auditStatusOptions = response.data;
    });
    this.getDicts("prodmanage_up_picking_type").then((response) => {
      this.pickingTypeOptions = response.data;
    });

    //初始化下拉框

    this.getlistprod();
    // this.getlistWarehouse();
    this.getlistpickingDepartment();
  },
  methods: {
    /** 查询生产管理生产上料列表 */
    getList() {
      this.loading = true;
      listUp(this.queryParams).then((response) => {
        this.upList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },

    getnum() {
      listnum(queryParams).then((response) => {
        this.numrOptions = response.rows;
        console.log(this.numrOptions);
      });
    },
    getlistpickingDepartment() {
      listpickingDepartment().then((response) => {
        this.pickingDepartmentOptions = response.rows;
        console.log(this.pickingDepartmentOptions)
      });
    },
    //查询生产任务单
    getlistprod() {
      listprod().then((response) => {
        this.productionOrderOptions = response.rows;
      });
    },

    //查询物料
    getstgoods() {
      listgood().then((response) => {
        this.goodsOptionss = response.rows;
      });
    },

    // 审核状态字典翻译
    auditStatusFormat(row, column) {
      return this.selectDictLabel(this.auditStatusOptions, row.auditStatus);
    },
    // 领料类型字典翻译
    pickingTypeFormat(row, column) {
      return this.selectDictLabel(this.pickingTypeOptions, row.pickingType);
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.open1 = false;
      this.aaa = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        upId: undefined,
        goodsId: undefined,
        code: undefined,
        auxiliaryCode: undefined,
        name: undefined,
        goodsModel: undefined,
        originalOrder: undefined,
        productionOrder: undefined,
        loadingQuantity: undefined,
        applyNum: undefined,
        actualNum: undefined,
        unit: undefined,
        lssuingWarehouse: undefined,
        isRework: undefined,
        costObject: undefined,
        costCode: undefined,
        productModel: undefined,
        costGroup: undefined,
        workNum: undefined,
        projectCode: undefined,
        availableStock: undefined,
        auxiliaryUnit: undefined,
        conversionRate: undefined,
        auxiliaryNum: undefined,
        planUnivalence: undefined,
        planPrice: undefined,
        univalence: undefined,
        price: undefined,
        customerBom: undefined,
        remark: undefined,
        date: undefined,
        guaranteePeriod: undefined,
        expiryDate: undefined,
        position: undefined,
        procedureNum: undefined,
        workProcedure: undefined,
        costCenter: undefined,
        locationNum: undefined,
        returnDimension: undefined,
        returnBook: undefined,
        checkedQuantity: undefined,
        createTime: undefined,
        createUser: undefined,
        updateTime: undefined,
        updateUser: undefined,
        isDel: undefined,
        auditStatus: undefined,
        printsNumber: undefined,
        oppositeAccount: undefined,
        backflushMark: undefined,
        pickingType: undefined,
        pickingDepartment: undefined,
        pickingUse: undefined,
        originalType: undefined,
        workshop: undefined,
        menuNum: undefined,
        prodLine: undefined,
        source: undefined,
        goodsOptions: undefined,
        pickingDepartment: undefined,
      };
      this.resetForm("form");
    },
     reset1() {
      this.form1 = {
        upId: undefined,
        goodsId: undefined,
        code: undefined,
        auxiliaryCode: undefined,
        name: undefined,
        goodsModel: undefined,
        originalOrder: undefined,
        productionOrder: undefined,
        loadingQuantity: undefined,
        applyNum: undefined,
        actualNum: undefined,
        unit: undefined,
        lssuingWarehouse: undefined,
        isRework: undefined,
        costObject: undefined,
        costCode: undefined,
        productModel: undefined,
        costGroup: undefined,
        workNum: undefined,
        projectCode: undefined,
        availableStock: undefined,
        auxiliaryUnit: undefined,
        conversionRate: undefined,
        auxiliaryNum: undefined,
        planUnivalence: undefined,
        planPrice: undefined,
        univalence: undefined,
        price: undefined,
        customerBom: undefined,
        remark: undefined,
        date: undefined,
        guaranteePeriod: undefined,
        expiryDate: undefined,
        position: undefined,
        procedureNum: undefined,
        workProcedure: undefined,
        costCenter: undefined,
        locationNum: undefined,
        returnDimension: undefined,
        returnBook: undefined,
        checkedQuantity: undefined,
        createTime: undefined,
        createUser: undefined,
        updateTime: undefined,
        updateUser: undefined,
        isDel: undefined,
        auditStatus: undefined,
        printsNumber: undefined,
        oppositeAccount: undefined,
        backflushMark: undefined,
        pickingType: undefined,
        pickingDepartment: undefined,
        pickingUse: undefined,
        originalType: undefined,
        workshop: undefined,
        menuNum: undefined,
        prodLine: undefined,
        source: undefined,
        goodsOptions: undefined,
        pickingDepartment: undefined,
      };
      this.resetForm("form1");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.upId);
      this.single = selection.length !== 1;
      this.multiple = !selection.length;
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.getstgoods();
      this.upNum = "实发数量";
      this.open = true;
      this.title = "添加生产管理生产上料";
    },
    /** 退料按钮操作 */
    handleUpdate(row) {
      this.reset();

      this.upNum = "退料数量";
      const upId = row.upId || this.ids;

      getUp(upId).then((response) => {
        listgood(response.data.lssuingWarehouse).then((response1) => {
          this.goodsOptionss = response1.rows;
          this.form = response.data;
          this.open = true;
          this.title = "退料";
        });
      });
    },
/** 修改按钮操作 */
    handleUpdatee(row) {
      this.reset();
      const upId = row.upId || this.ids
      getUp(upId).then(response => {
        this.form1 = response.data;
        this.open1 = true;
        this.title = "修改生产管理生产上料";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate((valid) => {
        if (valid) {
          //处理物料
          let tmp = this.form.name.split("|");
          this.form.goodsId = parseInt(tmp[0]);
          this.form.name = tmp[1];
          this.form.code = tmp[2];
          this.form.goodsModel = tmp[3];
          this.form.auxiliaryCode = tmp[4];
          //处理部门
          //console.log(this.form.pickingDepartment)
          //console.log(typeof( this.form.pickingDepartment))
          let tmp2 = this.form.pickingDepartment.split("|");
          this.form.pickingDepartment = tmp2[0];
          this.form.workshop = tmp2[1];
          this.form.prodLine = tmp2[2];

          if (this.form.upId != null) {
            this.msgSuccess("hello");
            returnGoods(this.form).then((response) => {
              this.msgSuccess("退料成功");
              this.open = false;
              this.getList();
            });
          } else {
            //查询库存数量
            addUp(this.form).then((response) => {
              this.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });

            // if (this.form.actualNum > this.numrOptions) {
            //   this.msgSuccess("库存不足");
            // } else {

            // }
          }
        }
      });
    },
    //选择物料，加载仓库
    addwarehouse(value) {

       listWarehouse(value).then((response) => {
         this.WarehouseOptions = response.rows;
       });
    },

    /** 删除按钮操作 */
    handleDelete(row) {
      const upIds = row.upId || this.ids;
      this.$confirm(
        '是否确认删除生产管理生产上料编号为"' + upIds + '"的数据项?',
        "警告",
        {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning",
        }
      )
        .then(function () {
          return delUp(upIds);
        })
        .then(response => {
          this.getList();
          this.msgSuccess(response.msg);
        });
    },
    /** 提交按钮 */
    submitFormm() {
      this.$refs["form1"].validate(valid => {
        if (valid) {
          if (this.form1.upId != null) {
            updateUp(this.form1).then(response => {
              this.msgSuccess("修改成功");
              this.open1 = false;
              this.getList();
            });
          } 
        }
      });
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$confirm("是否确认导出所有生产管理生产上料数据项?", "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(function () {
          return exportUp(queryParams);
        })
        .then((response) => {
          this.download(response.msg);
        });
    },
  },
};
</script>


















